package com.xiaoshuidi.cloud.module.contract.controller.admin.contract;

import com.alibaba.fastjson.JSONObject;
import com.xiaoshuidi.cloud.framework.common.pojo.CommonResult;
import com.xiaoshuidi.cloud.module.contract.dal.dataobject.contract.ContractSmsConfigDO;
import com.xiaoshuidi.cloud.module.contract.dal.dataobject.contract.OrderLateFeeVo;
import com.xiaoshuidi.cloud.module.contract.enums.ApiConstants;
import com.xiaoshuidi.cloud.module.contract.service.contract.ContractSmsConfigService;
import com.xiaoshuidi.cloud.module.system.api.apartment.ApartmentManageApi;
import com.xiaoshuidi.cloud.module.system.enums.apartment.ApartmentManageEnum;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;


@Slf4j
@Tag(name = "通知配置 - 短信配置")
@RestController
@RequestMapping(ApiConstants.NAME + "/contractSmsConfig")
@RequiredArgsConstructor
public class ContractSmsConfigController {

    @Resource
    private ContractSmsConfigService contractSmsConfigService;
    @Resource
    private ApartmentManageApi apartmentManageApi;

    /**
     * 查询配置
     * @param apartmentId
     * @return
     */
    @GetMapping("/getContractSmsConfig")
    public CommonResult<ContractSmsConfigDO> getContractSmsConfig(Long apartmentId) {
        return CommonResult.success(contractSmsConfigService.getContractSmsConfig(apartmentId));
    }

    /**
     * 修改通知配置
     * @param contractSmsConfigDO
     * @return
     */
    @PostMapping("/updateContractSmsConfig")
    public CommonResult<Boolean> updateOrderLateFee(ContractSmsConfigDO contractSmsConfigDO){
        return CommonResult.success(contractSmsConfigService.updateById(contractSmsConfigDO));
    }

    @PostMapping("/insertContractSmsConfig")
    public CommonResult<Boolean>insertOrderLateFee(ContractSmsConfigDO contractSmsConfigDO){
        log.info("保存滞纳金参数："+ JSONObject.toJSONString(contractSmsConfigDO));
        apartmentManageApi.updateApartment(contractSmsConfigDO.getApartmentId(), ApartmentManageEnum.INFORM_CONFIG.getCode());
        return CommonResult.success(contractSmsConfigService.save(contractSmsConfigDO));
    }
}
